﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI.Desktop
{
    public partial class frmCargarObservacion : Form
    {
        public frmCargarObservacion()
        {
            InitializeComponent();
            txtFecha.Enabled = false;
            txtHorario.Enabled = false;
            txtObservacion.Enabled = false;
            txtFecha.Visible = false;
            txtHorario.Visible = false;
            txtObservacion.Visible = false;
        }

        private void cbPaciente_Click(object sender, EventArgs e)
        {
            Business.Entities.Paciente pac = new Business.Entities.Paciente();
            DataSet dsPac = new DataSet();
            dsPac = pac.ObtenerListaPacientesHabilitados();
            ObtenerPacientes(dsPac);

        }

        private void ObtenerPacientes(DataSet dsPac)
        {
            cbPaciente.Text = "Seleccione el paciente";
            cbPaciente.DataSource = dsPac.Tables["Paciente"];
            cbPaciente.DisplayMember = dsPac.Tables["Paciente"].Columns[1].Caption.ToString();
        }

       

        private void btnCerrarTurnos_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                Business.Entities.Turno Tur = new Business.Entities.Turno();
                Business.Entities.Paciente Pac = new Business.Entities.Paciente();
               

                DataSet dsPac = new DataSet();
                DataTable dtTur = new DataTable();
                string Concatenado = cbPaciente.Text.ToString();
                dsPac = Pac.ObtenerListaPacientesConNombreApellido(Concatenado);

                string Id_Paciente = dsPac.Tables["Paciente"].Rows[0][0].ToString();
                dtTur = Tur.ObtenerTurnoHistorial(Id_Paciente);
                dtHistorial.DataSource = dtTur;
                
            }



            catch 
            {
                
            }
        
        
        
        }

        private void btnGuardarPaciente_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("¿Desea agregar  la observación a el turno con fecha " + txtFecha.Text.ToString() + " y hora "+txtHorario.Text.ToString()+"?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                Business.Entities.Turno Tur = new Business.Entities.Turno();
                Business.Entities.Paciente Pac = new Business.Entities.Paciente();

                DataSet dsTur = new DataSet();
                DataSet dsPac = new DataSet();
                string Concatenado = cbPaciente.Text.ToString();
                dsPac = Pac.ObtenerListaPacientesConNombreApellido(Concatenado);
                string Id_Paciente = dsPac.Tables["Paciente"].Rows[0][0].ToString();
                string fecha = txtFecha.Text;
                string hora = txtHorario.Text;
                dsTur = Tur.ConseguirTurno(Id_Paciente, fecha, hora);
                string id_turno = dsTur.Tables["Turnos"].Rows[0][0].ToString();
                string observacion = txtObservacion.Text;
                Tur.AgregarObservacion(id_turno, observacion);
                
                this.Close();
            }
        }

        private void dtHistorial_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtFecha.Text = dtHistorial.Rows[e.RowIndex].Cells[2].Value.ToString();
            txtHorario.Text = dtHistorial.Rows[e.RowIndex].Cells[3].Value.ToString();
            txtObservacion.Text = dtHistorial.Rows[e.RowIndex].Cells[4].Value.ToString();
            
        }
        }

       

       
        





    }

